import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
export class Http {
    constructor() {
        this.initOption();
        axios.interceptors.request.use(this.requestInterceptor, this.requestErrorInterceptor);
        axios.interceptors.response.use(this.responseInterceptor, this.responseErrorInterceptor);
    }
    public get(option: RequestOption): Promise<any> {
        return axios.get(option.url, option);
    }
    public post(option: RequestOption): Promise<any> {
        return axios.post(option.url, option);
    }
    public request(option: RequestOption): Promise<any> {
        return axios.request(option);
    }
    /** 初始化配置 */
    private initOption() {
        axios.defaults.baseURL = 'https://localhost:5001';
    }
    //#region Request Interceptor
    private requestInterceptor(option: AxiosRequestConfig): AxiosRequestConfig {
        return option;
    }
    private requestErrorInterceptor(error: any) {
        return Promise.reject(error);
    }
    //#endregion
    //#region Response Interceptor
    private responseInterceptor(option: AxiosResponse<any>): AxiosResponse<any> {
        return option;
    }
    private responseErrorInterceptor(error: any) {
        return Promise.reject(error);
    }
    //#endregion
}
const http: Http = new Http();
export default http;




